#-*- coding:utf8 -*-

__author__ = 'jh,Seo'
__version__ = '0.1'

from django.core.servers.basehttp import FileWrapper
from django.http import HttpResponse, Http404, HttpResponseRedirect
from django.template import Context, RequestContext
from django.shortcuts import render_to_response
from django.template.loader import get_template
from django.contrib.auth.models import User
from django.contrib.auth import logout
from django.core.mail import send_mail


import logging
log = logging.getLogger(__name__)
from models import *
from django.db.models import Q

from django.contrib.auth.decorators import login_required


from django.contrib.auth import authenticate
from django.contrib.auth import login as auth_login

from django.core import serializers
from django.utils import simplejson


import base64
import time
import hashlib
import datetime



from django.views.generic import View

class Controller(View):
    

    def get(self, request, *args, **kwargs ):
        
        data = ''
        
        #print request.GET
        #print args
        #print kwargs
        
        type = kwargs['type']
        
        log.info("type = " + type)
        
        if type is 'time':
            data = str(time.time())
            log.info(time.time())
        elif type is 'hash': 
            data = hashlib.sha256(str(time.time())).hexdigest()
            #data = hashlib.sha1(str(time.time())).hexdigest()
        elif type is 'date':
            data = datetime.datetime.now().strftime('%Y-%m-%d')
            
    
        #res['code'] = data
        res = [{'code':data}]
        return HttpResponse(simplejson.dumps(res), mimetype="application/json")
''' 
 
 def foo(self, request):
     log.error(request.method)
     
     if request.method == 'POST':
         log.info(str(request.POST['?a']))
         log.error('-_-')
         log.error(request.POST)
         
     res = [{'a':'b'}]
     return HttpResponse(simplejson.dumps(res), mimetype="application/json")
 '''
     
    
